package com.landian.commons.jpa.utils;

import com.google.common.base.MoreObjects;
import org.hibernate.criterion.MatchMode;

/**
 * LikeUtils
 *
 * @author caojl
 * @create 2017/11/07
 **/
public class LikeUtils {

    /**
     * 拼接为关键字查询
     * @param key
     * @return
     */
    public static String anywhere(String key){
        return MatchMode.ANYWHERE.toMatchString(MoreObjects.firstNonNull(key,""));
    }

    /**
     * 拼接为关键字查询
     * @param key
     * @return
     */
    public static String like(String key, MatchMode matchMode){
        return matchMode.toMatchString(MoreObjects.firstNonNull(key,""));
    }

    public static void main(String[] args) {
        String anywhere = MatchMode.ANYWHERE.toMatchString("asdf");
        System.out.println(anywhere);
    }
}
